package com.longtailvideo.jwplayer.view.skins 
{
                                                  import com.longtailvideo.jwplayer.utils.*;
                                                  import com.longtailvideo.jwplayer.view.interfaces.*;
                                                  import flash.display.*;
                                                  import flash.events.*;
                                                  import flash.text.*;
                                                  
                                                  public class SWFSkin extends com.longtailvideo.jwplayer.view.skins.SkinBase implements com.longtailvideo.jwplayer.view.interfaces.ISkin
                                                  {
                                                                                                    public function SWFSkin(arg1:flash.display.DisplayObject=null)
                                                                                                    {
                                                                                                                                                      super();
                                                                                                                                                      this.props = new com.longtailvideo.jwplayer.view.skins.SkinProperties();
                                                                                                                                                      if (arg1) 
                                                                                                                                                      {
                                                                                                                                                                                                        this.overwriteSkin(arg1);
                                                                                                                                                      }
                                                                                                                                                      return;
                                                                                                    }

                                                                                                    protected function overwriteSkin(arg1:flash.display.DisplayObject):void
                                                                                                    {
                                                                                                                                                      var newSkin:flash.display.DisplayObject;

                                                                                                                                                      var loc1:*;
                                                                                                                                                      newSkin = arg1;
                                                                                                                                                      if (newSkin is flash.display.Sprite) 
                                                                                                                                                      {
                                                                                                                                                                                                        _skin = newSkin as flash.display.Sprite;
                                                                                                                                                      }
                                                                                                                                                      else if (newSkin != null) 
                                                                                                                                                      {
                                                                                                                                                                                                        _skin = new flash.display.Sprite();
                                                                                                                                                                                                        _skin.addChild(newSkin);
                                                                                                                                                      }
                                                                                                                                                      if (_skin.getChildByName("controlbar")) 
                                                                                                                                                      {
                                                                                                                                                                                                        this.props["controlbar.size"] = _skin.getChildByName("controlbar").height;
                                                                                                                                                                                                        try 
                                                                                                                                                                                                        {
                                                                                                                                                                                                                                                          this.props["controlbar.margin"] = ((_skin.getChildByName("display") as flash.display.DisplayObjectContainer).getChildByName("back").width - _skin.getChildByName("controlbar").width) / 2;
                                                                                                                                                                                                        }
                                                                                                                                                                                                        catch (e:Error)
                                                                                                                                                                                                        {
                                                                                                                                                                                                                                                          props["controlbar.margin"] = 0;
                                                                                                                                                                                                        }
                                                                                                                                                      }
                                                                                                                                                      return;
                                                                                                    }

                                                                                                    public override function load(arg1:String=null):void
                                                                                                    {
                                                                                                                                                      var loc1:*=null;
                                                                                                                                                      if (arg1) 
                                                                                                                                                      {
                                                                                                                                                                                                        loc1 = new com.longtailvideo.jwplayer.utils.AssetLoader();
                                                                                                                                                                                                        loc1.addEventListener(flash.events.Event.COMPLETE, this.loadComplete);
                                                                                                                                                                                                        loc1.addEventListener(flash.events.ErrorEvent.ERROR, this.loadError);
                                                                                                                                                                                                        loc1.load(arg1, flash.display.DisplayObject);
                                                                                                                                                      }
                                                                                                                                                      else if (_skin.numChildren == 0) 
                                                                                                                                                      {
                                                                                                                                                                                                        sendError("Skin must load from URL if skin is empty.");
                                                                                                                                                      }
                                                                                                                                                      return;
                                                                                                    }

                                                                                                    protected function loadComplete(arg1:flash.events.Event):void
                                                                                                    {
                                                                                                                                                      var loc1:*=com.longtailvideo.jwplayer.utils.AssetLoader(arg1.target);
                                                                                                                                                      this.overwriteSkin(flash.display.DisplayObjectContainer(loc1.loadedObject).getChildByName("player"));
                                                                                                                                                      dispatchEvent(new flash.events.Event(flash.events.Event.COMPLETE));
                                                                                                                                                      return;
                                                                                                    }

                                                                                                    protected function loadError(arg1:flash.events.ErrorEvent):void
                                                                                                    {
                                                                                                                                                      sendError(arg1.text);
                                                                                                                                                      return;
                                                                                                    }

                                                                                                    public override function getSkinProperties():com.longtailvideo.jwplayer.view.skins.SkinProperties
                                                                                                    {
                                                                                                                                                      return this.props;
                                                                                                    }

                                                                                                    public override function getSkinElement(arg1:String, arg2:String):flash.display.DisplayObject
                                                                                                    {
                                                                                                                                                      var component:String;
                                                                                                                                                      var element:String;
                                                                                                                                                      var result:flash.display.DisplayObject;
                                                                                                                                                      var cls:Class;
                                                                                                                                                      var dup:*;
                                                                                                                                                      var comp:flash.display.DisplayObjectContainer;

                                                                                                                                                      var loc1:*;
                                                                                                                                                      cls = null;
                                                                                                                                                      dup = undefined;
                                                                                                                                                      comp = null;
                                                                                                                                                      component = arg1;
                                                                                                                                                      element = arg2;
                                                                                                                                                      if (component == "dock") 
                                                                                                                                                      {
                                                                                                                                                                                                        try 
                                                                                                                                                                                                        {
                                                                                                                                                                                                                                                          cls = _skin.loaderInfo.applicationDomain.getDefinition("dockbutton") as Class;
                                                                                                                                                                                                                                                          dup = new cls();
                                                                                                                                                                                                                                                          dup.transform = _skin.transform;
                                                                                                                                                                                                                                                          dup.filters = _skin.filters;
                                                                                                                                                                                                                                                          dup.cacheAsBitmap = _skin.cacheAsBitmap;
                                                                                                                                                                                                                                                          dup.opaqueBackground = _skin.opaqueBackground;
                                                                                                                                                                                                                                                          return (dup as flash.display.Sprite).getChildByName("back") as flash.display.Sprite;
                                                                                                                                                                                                        }
                                                                                                                                                                                                        catch (e:Error)
                                                                                                                                                                                                        {
                                                                                                                                                                                                        };
                                                                                                                                                      }
                                                                                                                                                      if (component == "playlist") 
                                                                                                                                                      {
                                                                                                                                                                                                        if (element == "masker" || element == "background") 
                                                                                                                                                                                                        {
                                                                                                                                                                                                                                                          if (element == "background") 
                                                                                                                                                                                                                                                          {
                                                                                                                                                                                                                                                                                                            element = "back";
                                                                                                                                                                                                                                                          }
                                                                                                                                                                                                                                                          comp = _skin.getChildByName(component) as flash.display.DisplayObjectContainer;
                                                                                                                                                                                                                                                          if (comp) 
                                                                                                                                                                                                                                                          {
                                                                                                                                                                                                                                                                                                            return comp.getChildByName(element);
                                                                                                                                                                                                                                                          }
                                                                                                                                                                                                        }
                                                                                                                                                      }
                                                                                                                                                      result = super.getSkinElement(component, element);
                                                                                                                                                      if (result && !(result is flash.text.TextField)) 
                                                                                                                                                      {
                                                                                                                                                                                                        result = com.longtailvideo.jwplayer.utils.Draw.clone(result as flash.display.Sprite);
                                                                                                                                                      }
                                                                                                                                                      return result;
                                                                                                    }

                                                                                                    public function getTranslatedSkinElement(arg1:String, arg2:String):flash.display.DisplayObject
                                                                                                    {
                                                                                                                                                      var loc2:*=NaN;
                                                                                                                                                      var loc3:*=NaN;
                                                                                                                                                      var loc4:*=null;
                                                                                                                                                      var loc5:*=null;
                                                                                                                                                      var loc6:*=null;
                                                                                                                                                      var loc7:*=null;
                                                                                                                                                      var loc8:*=null;
                                                                                                                                                      var loc1:*=super.getSkinElement(arg1, arg2);
                                                                                                                                                      var loc9:*=arg1;
                                                                                                                                                      switch (loc9) 
                                                                                                                                                      {
                                                                                                                                                                                                        case "controlbar":
                                                                                                                                                                                                        {
                                                                                                                                                                                                                                                          loc2 = arg2.indexOf("Button");
                                                                                                                                                                                                                                                          loc3 = arg2.indexOf("Slider");
                                                                                                                                                                                                                                                          if (loc2 > 0) 
                                                                                                                                                                                                                                                          {
                                                                                                                                                                                                                                                                                                            loc4 = arg2.substr(loc2, arg2.length);
                                                                                                                                                                                                                                                                                                            loc5 = arg2.substr(0, loc2 + 6);
                                                                                                                                                                                                                                                                                                            loc9 = loc4;
                                                                                                                                                                                                                                                                                                            switch (loc9) 
                                                                                                                                                                                                                                                                                                            {
                                                                                                                                                                                                                                                                                                                                                              case "Button":
                                                                                                                                                                                                                                                                                                                                                              {
                                                                                                                                                                                                                                                                                                                                                                                                                loc1 = this.getSubElement("icon", loc1);
                                                                                                                                                                                                                                                                                                                                                                                                                break;
                                                                                                                                                                                                                                                                                                                                                              }
                                                                                                                                                                                                                                                                                                                                                              case "ButtonBack":
                                                                                                                                                                                                                                                                                                                                                              {
                                                                                                                                                                                                                                                                                                                                                                                                                if (loc6 = super.getSkinElement(arg1, loc5) as flash.display.MovieClip) 
                                                                                                                                                                                                                                                                                                                                                                                                                {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                  (loc6.getChildByName("icon") as flash.display.DisplayObject).alpha = 0;
                                                                                                                                                                                                                                                                                                                                                                                                                                                                  loc1 = loc6;
                                                                                                                                                                                                                                                                                                                                                                                                                }
                                                                                                                                                                                                                                                                                                                                                                                                                break;
                                                                                                                                                                                                                                                                                                                                                              }
                                                                                                                                                                                                                                                                                                            }
                                                                                                                                                                                                                                                          }
                                                                                                                                                                                                                                                          else if (loc3 > 0) 
                                                                                                                                                                                                                                                          {
                                                                                                                                                                                                                                                                                                            loc7 = arg2.substr(loc3, arg2.length);
                                                                                                                                                                                                                                                                                                            loc8 = arg2.substr(0, loc3 + 6);
                                                                                                                                                                                                                                                                                                            loc1 = super.getSkinElement(arg1, loc8);
                                                                                                                                                                                                                                                                                                            loc9 = loc7;
                                                                                                                                                                                                                                                                                                            switch (loc9) 
                                                                                                                                                                                                                                                                                                            {
                                                                                                                                                                                                                                                                                                                                                              case "SliderRail":
                                                                                                                                                                                                                                                                                                                                                              {
                                                                                                                                                                                                                                                                                                                                                                                                                loc1 = this.getSubElement("rail", loc1);
                                                                                                                                                                                                                                                                                                                                                                                                                break;
                                                                                                                                                                                                                                                                                                                                                              }
                                                                                                                                                                                                                                                                                                                                                              case "SliderBuffer":
                                                                                                                                                                                                                                                                                                                                                              {
                                                                                                                                                                                                                                                                                                                                                                                                                if (arg2 != "volumeSliderBuffer") 
                                                                                                                                                                                                                                                                                                                                                                                                                {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                  loc1 = this.getSubElement("mark", loc1);
                                                                                                                                                                                                                                                                                                                                                                                                                }
                                                                                                                                                                                                                                                                                                                                                                                                                else 
                                                                                                                                                                                                                                                                                                                                                                                                                {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                  loc1 = null;
                                                                                                                                                                                                                                                                                                                                                                                                                }
                                                                                                                                                                                                                                                                                                                                                                                                                break;
                                                                                                                                                                                                                                                                                                                                                              }
                                                                                                                                                                                                                                                                                                                                                              case "SliderProgress":
                                                                                                                                                                                                                                                                                                                                                              {
                                                                                                                                                                                                                                                                                                                                                                                                                if (arg2 != "volumeSliderProgress") 
                                                                                                                                                                                                                                                                                                                                                                                                                {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                  loc1 = this.getSubElement("done", loc1);
                                                                                                                                                                                                                                                                                                                                                                                                                }
                                                                                                                                                                                                                                                                                                                                                                                                                else 
                                                                                                                                                                                                                                                                                                                                                                                                                {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                  loc1 = null;
                                                                                                                                                                                                                                                                                                                                                                                                                }
                                                                                                                                                                                                                                                                                                                                                                                                                break;
                                                                                                                                                                                                                                                                                                                                                              }
                                                                                                                                                                                                                                                                                                                                                              case "SliderThumb":
                                                                                                                                                                                                                                                                                                                                                              {
                                                                                                                                                                                                                                                                                                                                                                                                                loc1 = this.getSubElement("icon", loc1);
                                                                                                                                                                                                                                                                                                                                                                                                                break;
                                                                                                                                                                                                                                                                                                                                                              }
                                                                                                                                                                                                                                                                                                            }
                                                                                                                                                                                                                                                          }
                                                                                                                                                                                                                                                          else if (arg2 == "back" || arg2 == "shade") 
                                                                                                                                                                                                                                                          {
                                                                                                                                                                                                                                                                                                            super.getSkinElement(arg1, arg2);
                                                                                                                                                                                                                                                          }
                                                                                                                                                                                                                                                          break;
                                                                                                                                                                                                        }
                                                                                                                                                                                                        case "display":
                                                                                                                                                                                                        {
                                                                                                                                                                                                                                                          loc9 = arg2;
                                                                                                                                                                                                                                                          switch (loc9) 
                                                                                                                                                                                                                                                          {
                                                                                                                                                                                                                                                                                                            case "errorIcon":
                                                                                                                                                                                                                                                                                                            {
                                                                                                                                                                                                                                                                                                                                                              if (loc1["icn"]) 
                                                                                                                                                                                                                                                                                                                                                              {
                                                                                                                                                                                                                                                                                                                                                                                                                loc1 = loc1["icn"];
                                                                                                                                                                                                                                                                                                                                                              }
                                                                                                                                                                                                                                                                                                                                                              break;
                                                                                                                                                                                                                                                                                                            }
                                                                                                                                                                                                                                                          }
                                                                                                                                                                                                        }
                                                                                                                                                      }
                                                                                                                                                      return loc1;
                                                                                                    }

                                                                                                    internal function getSubElement(arg1:String, arg2:flash.display.DisplayObject):flash.display.DisplayObject
                                                                                                    {
                                                                                                                                                      var loc1:*=null;
                                                                                                                                                      if (arg2) 
                                                                                                                                                      {
                                                                                                                                                                                                        loc1 = arg2[arg1];
                                                                                                                                                      }
                                                                                                                                                      return loc1;
                                                                                                    }

                                                                                                    public override function getSWFSkin():flash.display.Sprite
                                                                                                    {
                                                                                                                                                      return _skin;
                                                                                                    }

                                                                                                    internal var props:com.longtailvideo.jwplayer.view.skins.SkinProperties;
                                                  }
}
